<!-- 缴费添加 -->
<template>
    <div>
        <el-dialog center :title="form.id?'修改缴费':'新增缴费'" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
            <el-form ref="form" :model="form" label-width="100px" style="margin-left:80px">
                <el-form-item label="费用类型：">
                    <el-select v-model="form.type" placeholder="请选择">
                        <el-option v-for="(item,index) in type" :key="index" :label="item.name" :value="item.name">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="金额：">
                    <el-input v-model="form.price" style="width:218px"></el-input>
                </el-form-item>
                <el-form-item label="账期：">
                    <el-date-picker v-model="data" 
                    value-format="yyyy-MM-dd"
                    type="daterange" align="right" unlink-panels range-separator="至"
                        start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"
                        style="width:218px">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="小区：">
                    <el-cascader v-model="form.buildingid"  :options="tableList" :props="propstag" clearable @change="changeVal"></el-cascader>
                </el-form-item>
                <el-form-item label="缴费房间：">
                    <div>
                        <el-radio v-model="radio" :label="1">全部</el-radio>
                        <el-radio v-model="radio" :label="2">部分房间</el-radio>
                    </div>
                    <el-input type="textarea"  style="width:218px;line-height: 2.5;"
                        :disabled="true"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="off()">取 消</el-button>
                <el-button type="primary" @click="add()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { feetype ,builList,addfee} from '@/api/fee'
export default {
    namespace: 'addfee',
    props: {
        dialogVisible: {
            type: Boolean,
            default: false
        },
        handleClickdata: {
            type: Object,
            default: () => { }
        },
    },
    data() {
        return {
            form: {
                id:0,
                type:"",
                price:"",
                buildingid:'',
                houseids:[]
            },
            data:"",
            
            radio: '1',
            pickerOptions: {
                shortcuts: [{
                    text: '本月',
                    onClick(picker) {
                        picker.$emit('pick', [new Date(), new Date()]);
                    }
                }, {
                    text: '今年至今',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date(new Date().getFullYear(), 0);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近六个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setMonth(start.getMonth() - 6);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            type: [],
            propstag: {
                value: 'id',
                label: 'name',
                children: 'children',
                checkStrictly: true,
                emitPath:false
            },
            tableList:[],
            
        };
    },
    created() {
        this.getfeetype()
        // 楼栋列表
        this.GetBuillist()
    },
    watch:{
        handleClickdata:{
            handler(val){
                if(val){
                    this.form = val
                    for(let i in this.form){
                        this.form[i] = val[i]
                        if (i === 'building') {
                            this.buildingid = val.buildingid
                        }
                        
                    }
                }
            }
        }
    },
    // updated(){
    //     this.form = this.handleClickdata
    // },
    methods: {
        // 缴费类型
        async getfeetype() {
            let res = await feetype()
            // console.log(res);
            if (res.errCode == 10000) {
                this.type = res.data.list
                // console.log(this.type);
            }
        },
        // 添加
        async add(){
            this.form.begindate = this.data[0]//这是啥
            this.form.enddate=this.data[1]
            let res = await addfee(this.form)
            console.log(res);
            if(res.errCode==10000){
                let msg = this.form.id?'修改成功':'添加成功'
                this.$message({
                    message:msg,
                    type: 'success',
                });
            }
            this.$emit('isclose', false, true,{},{})
        },
        // 楼栋列表
        async GetBuillist() {
            let res = await builList()
            // console.log(res);
            if (res.errCode == 10000) {
                this.tableList = res.data.list
            }
        },
        // 楼栋id
        changeVal(val) {
            this.$store.commit('tree/setPid', val)
        },
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    this.$emit('isclose', false,)
                    this.form = {} 
                }) 
                .catch(_ => { });
        },
        off() {
            this.$emit('isclose', false,)
            this.form = {}
        },
        sure() {

        },

    }
}
</script>

<style lang="less" scoped>

</style>